package com.moon.game.command.guest.sys;

import java.util.ArrayList;
import java.util.List;

import com.moon.game.command.BaseCmd;
import com.moon.game.command.RequestSession;
import com.moon.game.config.GlobalConfig;
import com.moon.game.exception.GException;
import com.moon.game.manager.NoticeMG;
import com.moon.game.resource.model.Notice;
import com.moon.game.util.SqlMapConfigData;
import com.moon.game.util.Utils;

/**
 * @description 查询所有公告
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-7-25 下午3:13:31
 */
public class QueryAllNoticeCmd extends BaseCmd {

	@Override
	protected void runOnce(RequestSession req) throws GException {
		switch (req.getStatus()) {
			case STATU_INIT:
				doInit(req);
				break;
			case STATU_CHECK:
				doCheckSelf(req);
				break;
			case STATU_RETURN:
				doResponse(req);
				break;
			default:
				break;
		}
	}

	@Override
	protected void doResponse(RequestSession req) throws GException {
		@SuppressWarnings("static-access")
		List<Notice> notices = NoticeMG.instance.getNotices();
		List<Notice> simpleNotices = new ArrayList<Notice>();
		if (notices != null) {
			for (Notice notice : notices) {
				Notice n = new Notice();
				n.setId(notice.getId());
				n.setName(notice.getName());
				simpleNotices.add(n);
			}
		}
		req.setVO("notices", simpleNotices);
		response(req, req.getClientResponse());
	}
}
